package org.example.two;

import com.rabbitmq.client.Channel;
import org.example.utils.RabbitMqUtil;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 消费线程1 ,同一个队列中的消息,被多个消费者轮训消费
 */
public class Work1 {
    public static final String QUEUE_NAME = "ONE.PRODUCER";
    public static final String workName = "work1";

    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMqUtil.getChannel();

        System.out.println(workName + "等待消费");
        channel.basicConsume(QUEUE_NAME,true,(message,delivery) -> {
            System.out.println(workName+"消费了: " + new String(delivery.getBody()));
        },message -> {
            System.out.println(workName+"取消了: " + message);
        });
    }
}
